class Solution
{
public:
    string convertToBase7(int num)
    {
        if (num == 0)
        {
            return "0";
        }
        bool minus = num < 0;
        num = abs(num);
        string reversed_result;
        while (num)
        {
            reversed_result += static_cast<char>('0' + num % 7);
            num /= 7;
        }
        if (minus)
        {
            reversed_result += "-";
        }
        return string(reversed_result.rbegin(), reversed_result.rend());
    }
};